import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 黎鹤舞
 * Date: 2023-11-01
 * Time: 23:35
 */
public class Test {

    //输入一个数，把这个数的二进制的偶数位和奇数位进行交换
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入一个正整数:");
        int num = scanner.nextInt();
        //计算偶数位信息 并右移
        int evenNum = num & 0xaaaaaaaa;
        evenNum >>= 1;
        //计算奇数位信息，并左移
        int oddNum = num & 0x55555555;
        oddNum <<= 1;
        int swap = oddNum + evenNum;
        System.out.println("after swap : " +  swap);
    }


    //输入一个数，返回其二进制中1的个数
    public static void main4(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入这个数:");
        int num = scanner.nextInt();
        int count = 0;

        while(num != 0) {
            if((num & 1) == 1) {
                count ++;
            }
            num >>= 1;
        }
        System.out.println(count);
    }

    //求出0～999之间的所有“水仙花数”并输出
    public static void main3(String[] args) {

        int tempI = 0;
        for (int i = 100; i <999 ; i++) {
            tempI = i;
            int firstNum = i % 10;
            tempI = tempI / 10;
            int secondNum = tempI % 10;
            tempI = tempI / 10;
            int thirdNum = tempI % 10;

            if(Math.pow(firstNum,3) + Math.pow(secondNum,3) + Math.pow(thirdNum,3) == i) {
                System.out.println(i);
            }
        }

    }

    //求最大公约数 -辗转相除法
    public static void main2(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入需要求最大公约数的两个数:");
        int m = scanner.nextInt();
        int n = scanner.nextInt();
        int r = m % n;
        while(r != 0) {
            m = n;
            n = r;
            r = m % n;
        }
        System.out.println("最大公约数是:" + n);
    }


    //输出9*9乘法表
    public static void main1(String[] args) {

        for (int i = 1; i <=9 ; i++) {
            for (int j = 1; j <=i ; j++) {
                System.out.print(j + " * " + i + " = " + i*j + " ");
            }
            System.out.println();
        }

    }
}
